import wx

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title = '滑块', size = (500, 800))
        panel = wx.Panel(self)
        # 设置字体字号的范围
        self.slider = wx.Slider(panel, value = 24,
                           minValue= 12, maxValue = 96)
        # btn = wx.Button(panel, label = '获取当前值')
        self.slider.Bind(wx.EVT_SLIDER, self.on_slider)
        self.text = wx.StaticText(panel, label = 'Hello World!')
        # 设置一个垂直布局
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.slider)
        vbox.Add(self.text)
        panel.SetSizer(vbox)
        self.Show()

    # 滑块的滚动事件
    def on_slider(self, event):
        # print(f'滑块在变化了，当前值：{self.slider.GetValue()}')
        # 获取当前窗体的字体对象
        font = self.GetFont()
        font.SetPointSize(self.slider.GetValue())
        self.text.SetFont(font)

app = wx.App()
window = MyFrame()
app.MainLoop()